import request from "@/utils/request";

/** 文件管理模块开始 */

export function queryFile(query) {
  return request({
    url: "/api/file/file/queryFile",
    method: "get",
    params: query,
  });
}

export function queryFileTypeName() {
  return request({
    url: "/api/file/file/queryFileTypeName",
    method: "get",
  });
}

export function deleteFile(data) {
  return request({
    url: "/api/file/file/deleteFile",
    method: "post",
    params: {
      id: data,
    },
  });
}

export function downloadFile(data) {
  return request({
    url: "/api/file/file/downloadFile",
    method: "post",
    responseType: "blob",
    data,
  });
}

export function addFolder(id, originalFilename, parentId) {
  return request({
    url: "/api/file/file/addFolder",
    method: "post",
    params: {
      id: id,
      originalFilename: originalFilename,
      parentId: parentId,
    },
  });
}

/* 上传文件 */
export function uploadFile(file) {
  const data = new FormData();
  data.append("file", file);
  return request({
    url: "/api/file/minio/uploadFile",
    method: "post",
    data,
  });
}

/* 预览文件 */
export function filePreview(fileUrl) {
  return request({
    url: "/api/file/minio/preview",
    method: "get",
    params: { minFileName: fileUrl },
  });
}

/* 下载文件 */
export function fileDownload(url) {
  return request({
    url: "/api/file/minio/download",
    method: "get",
    params: { minFileName: url },
    responseType: "blob",
  });
}

//上传文件-简易
export function uploadFileRequest(file) {
  const data = new FormData();
  data.append("file", file);
  return request({
    url: "/management-admin/file/uploadFileSimple",
    method: "post",
    data,
  });
}

/** 文件管理模块结束 */

//分片上传1
export function uploadPartOneRequest(data) {
  return request({
    url: "/management-admin/file/uploadPartOne",
    method: "post",
    data,
  });
}
let http = {
  post(url, data = {}, config) {
    return request({ url, data, ...config, method: "POST" });
  },
};

//分片上传2
export function uploadPartTwoRequest(data, config) {
  // debugger;
  return http.post("/management-admin/file/uploadPartTwo", data, {
    ...config,
    noloding: true,
  });
}

//资源定位符查询
export function queryResourceLocationRequest(params) {
  return request({
    url: "/management-admin/file/getPositionInfo",
    method: "get",
    params,
  });
}

//资源定位符上传
export function uploadResourceLocationRequest(data) {
  return request({
    url: "/management-admin/file/uploadFileSimple",
    method: "post",
    data,
  });
}
